<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>管理员注册</title>
<jsp:include page="/commons/common-js.jsp"></jsp:include>
</head>
<body style="background-color: #F3F3F3">
    <div class="easyui-dialog" title="管理员注册" data-options="closable:false,draggable:false" style="width:400px;height:300px;padding:10px;">
    <form id="ukeyInfoForm">
       	<div style="margin-left: 50px;margin-top: 10px;">
       		<div style="margin-bottom:10px;">
	            <div>
	            	用&nbsp;&nbsp;户&nbsp;&nbsp;名: <input name="username" class="easyui-textbox" data-options="iconCls:'icon-man',required:true,validType:['username','username_isExist'],missingMessage:'请输入用户名'" style="width:200px;height:32px"/>
	            </div>
	        </div>
	        <div style="margin-bottom:10px">
	            <div>
	            	密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码: <input id="password" name="password" class="easyui-textbox" type="password" style="width:200px;height:32px" data-options="iconCls:'icon-lock',required:true,validType:'length[6,18]',missingMessage:'请输入密码'"/>
	            </div>
	        </div>
	        <div style="margin-bottom:10px">
	            <div>
	            	确认密码 : <input name="repassword" class="easyui-textbox" type="password" style="width:200px;height:32px" data-options="iconCls:'icon-lock',required:true,validType:'equalTo[\'#password\']', missingMessage:'请再输入一次密码'"/>
	            </div>
	        </div>
	        <div style="margin-bottom:10px;">
	            <div>
	            	电话号码 : <input name="phone" class="easyui-numberbox" data-options="required:true,validType:'phone',missingMessage:'请输入电话号码'" style="width:200px;height:32px"/>
	            </div>
	        </div>
	        <div>
	            <a id="login" class="easyui-linkbutton" iconCls="icon-ok" style="width:100px;height:32px;margin-left: 45px">去登录</a>
	             <a id="register" class="easyui-linkbutton" iconCls="icon-ok" style="width:100px;height:32px;margin-left: 25px">注册</a>
	        </div>
       	</div>
       	</form>
    </div>
    
    <script type="text/javascript">
    	$("#register").click(function(){
    		
    		var username = $("[name=username]").val();
    		var password = $("[name=password]").val();
    		var phone = $("[name=phone]").val();
    		$.ajax({
	    		type:"post",
	    		url:"/manager/doRegister",
	    		data:{"username":username,"password":password,"phone":phone},
	    		success:function(data){
	        		if(data.status == 200){
	        			alert("注册成功，请登录！");
	        		}else{
	        			alert(data.msg);
	        			return ;
	        		} 
	        	}
	    	});
    	});
    	
    	$("#login").click(function(){
    		window.location.href="/manager/login";
    	});
    	
    	
    	//用户名是否存在校验
    	$.extend($.fn.validatebox.defaults.rules, {
    	    username: {
    	        validator: function(value,param){
    	            //数字、字母、下划线，6-20长度
    	            var t = /^[a-zA-Z0-9_\u4e00-\u9fa5]{6,20}$/;
    	            //var t = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;只能含有汉字、数字、字母、下划线  长度并没有限制
    	            return t.test(value);
    	        },
    	        message:'只能含有汉字、数字、字母、下划线,并且长度6-20!'
    	    }
    	});
    	
    	
    	//密码校验
    	 $.extend($.fn.validatebox.defaults.rules, {
        /*必须和某个字段相等*/
        equalTo: {
						validator: function (value, param) {
						return value == $(param[0]).val(); 
					}, 
					message: '两次密码不一致' 
			}
       });

    	   	
     	//电话号码验证
    	$.extend($.fn.validatebox.defaults.rules, {
    		phone:{
    			validator:function(value,param){
    				var t = /^0?(13[0-9]|15[0123456789]|18[0-9]|17[0-9])[0-9]{8}$/;
    				return t.test(value);
    			},
    			message:'请输入正确的手机号'
    		}
    	}); 
    </script>
</body>
</html>